package com.hb.umsp.service;

import com.hb.umsp.entity.HbUser;
import com.hb.umsp.mapper.HbUserMapper;
import com.hb.umsp.util.token.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserService {

    @Autowired
    HbUserMapper hbUserMapper;

    @Autowired
    TokenUtil tokenUtil;

    public HbUser findHhUser(String username) {

        return hbUserMapper.selectByUsername(username);
    }

    public HbUser findHbUserByToken(String token){
        Map<String,String> map = tokenUtil.parseToken(token);
        String username = map.get("userId");
        return hbUserMapper.selectByUsername(username);
    }

    public List<HbUser> selectUserToMenuGrpByToken(String token) {
        Map<String,String> map = tokenUtil.parseToken(token);
        String username = map.get("userId");
        return hbUserMapper.selectUserToMenuGrp(username);
    }

    public List<HbUser> findUser(HbUser hbUser) {
        return hbUserMapper.selectUser(hbUser);
    }

    public void insertUser(HbUser hbUser) {

        hbUserMapper.insertSelective(hbUser);
    }

    public void updateUser(HbUser hbUser) {

        hbUserMapper.updateUser(hbUser);
    }
}
